import React, { memo, createContext, useState, useContext } from "react";

const MyContext = createContext();

const Son1 = () => {
  let count = useContext(MyContext);
  return <h3>子组件 {count} </h3>;
};

const index = memo(() => {
  const [count, setCount] = useState(123);
  return (
    <div>
      <MyContext.Provider value={count}>
        <Son1></Son1>
        <button
          onClick={(e) => {
            setCount(count + 100);
          }}
        >
          按钮改context
        </button>
      </MyContext.Provider>
    </div>
  );
});

export default index;
